package wu.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import wu.mapper.DeptMapper;
import wu.pojo.Dept;
import wu.service.DeptService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DS("master_1")
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

//     public List<Dept> findData(Integer page, Integer limit)
    @Override
    public List<Dept> findData() {
        //6.进行分页,写完这个还一定要嫁一个拦截器啊，也就是config文件夹的MyBatisPlusConfig文件---------------------------------------------------------------------------
        //Page里的参数默认1和10，IPage<Dept> productIPage = new Page<>(page,limit);
        //但是我发现 这个竟然不需要写  我也母鸡啊
        //转折了 ，我发现不写配置类 会返回全部数据，不能达到分页的效果啊  哈哈
        IPage<Dept> productIPage = new Page<>(1,2);
        QueryWrapper<Dept> wrapper = new QueryWrapper<>();
        wrapper.like("dname","发");
        IPage<Dept> result = deptMapper.selectPage(productIPage, wrapper);//根据分页查所有数据
        List<Dept> list = result.getRecords();
        return list;
    }


    //xml文件实现
    @Override
    @DS("slave_2")
    public List<Dept> xml() {
        return deptMapper.xml();
    }


    //注解形式开发
    @Override
    public Dept findAnnotion(Long id) {
        return deptMapper.findAnnootion(id);
    }


}
